package com.example.travel.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.travel.R;
import com.example.travel.bean.AddDynamic;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class AddActivity2 extends AppCompatActivity {
    Button fabu;
    private EditText et1,et2 ;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bmob.initialize(this, "725506ecca6f5fd13ccdb5541cddf851");
        setContentView(R.layout.fabudongtai);
        fabu =(Button)this.findViewById(R.id.fabu);
        et1 = (EditText) findViewById(R.id.et1);
        et2 = (EditText) findViewById(R.id.et2);
        fabu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String titleName=et1.getText().toString();
                String descridle=et2.getText().toString();
                AddDynamic addDynamic = new AddDynamic();
                addDynamic.setTitle(titleName);//titleName为用户输入的标题
//                lostInfomationReq.setPhoneNum(num);//num为用户输入的号码
                addDynamic.setDesc(descridle);//descridle为信息描述
                addDynamic.save(new SaveListener<String>() {
                    @Override
                    public void done(String s, BmobException e) {
                        if (e == null) {
                            Toast.makeText(AddActivity2.this,
                                    "动态信息发布成功！", Toast.LENGTH_LONG).show();

                            //成功后提示主界面刷新数据
                            Intent intent = new Intent();
                            setResult(RESULT_OK, intent);
                            //成功后将页面销毁
                            finish();
                        } else {
                            Toast.makeText(AddActivity2.this,
                                    "动态信息发布失败！", Toast.LENGTH_LONG).show();
                        }
                    }
                });
            }
        });




    }
}
